export interface VisaItemType {
  id: number;
  name: string;
}

export interface AllowableCountryItemType {
  id: number;
  name: string;
  star_image_url: string;
}

// 大洲枚举
export enum ContinentsEnum {
  // 美洲
  AF = "AF",
  // 南极洲
  AN = "AN",
  // 亚洲
  AS = "AS",
  // 欧洲
  EU = "EU",
  // 北美洲
  NA = "NA",
  // 大洋洲
  OC = "OC",
  // 南美洲
  SA = "SA",
}

export interface AllowableCountryListParamsType {
  continents: ContinentsEnum;
}

export interface BannerListItemType {
  id: number;
  name: string;
  image_url: string;
  path: string;
}

export interface UploadImageResponseType {
  data: { name: string; url: string };
  name: string;
  fileName: string;
  message: string;
  success: boolean;
  uploaded: number;
  url: string;
}

export interface ImageItemType {
  id: number;
  url: string;
}

// 签证类型列表
export function getVisaList() {
  return uni.$u.http.get<VisaItemType[]>("/api/star/visa");
}

/**
 * @description 获取允许的国家列表
 * @param {AllowableCountryListParamsType} params
 * @returns {Promise<AllowableCountryItemType[]>}
 * @example getAllowableCountryList({continents: ContinentsEnum.AS})
 */
export function getAllowableCountryList(
  params: AllowableCountryListParamsType
) {
  return uni.$u.http.get<AllowableCountryItemType[]>(
    "/api/star/country?continents=AS",
    {
      params,
    }
  );
}

// 轮播图
export function getBannerList() {
  return uni.$u.http.get<BannerListItemType[]>("/api/wx/banner");
}

// 上传图片
export function uploadImage(filePath: string) {
  return uni.$u.http.upload<UploadImageResponseType>("/api/file/upload", {
    filePath,
  });
}

// 删除已上传的图片
export function deleteUploadImage(infoId: number, imageId: number) {
  return uni.$u.http.delete<any>(
    `/api/visa/userinfo/${infoId}/image/${imageId}`
  );
}
